package com.zhiyou.springcloud.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.zhiyou.springcloud.bean.Msg;
import com.zhiyou.springcloud.bean.educationtype;
import com.zhiyou.springcloud.bean.safeeducation;
import com.zhiyou.springcloud.service.SafeEducationService;

@Controller
public class SafeEducationController {

	@Autowired
	SafeEducationService safeEducationService;
	
	@RequestMapping("/getSafeEducationsByTid")
	@ResponseBody
	public Msg getAllSafeEducations(Integer etid){
		List<safeeducation> list=safeEducationService.getSafeEducationsByTid(etid);
		return Msg.cuccess().add("list", list);
	}
	//获取所有安全教育类型
	@RequestMapping("/getAllTypes")
	@ResponseBody
	public Msg getAllTypes() {
		List<educationtype> list=safeEducationService.getAllTypes();
		return Msg.cuccess().add("list", list);
	}
	//当点击一条安全教育时，那么就触发ajax通过eid修改阅读次数
	@RequestMapping("/addReadNo")
	@ResponseBody
	public Msg addReadNo(Integer eid) {
		
		return Msg.cuccess();
	}
	//通过eid获取当前安全教育的全部信息
	@RequestMapping("/getSafeDetailsByEid")
	@ResponseBody
	public Msg getSafeDetailsByEid(Integer eid) {
		safeeducation safeeducation=new safeeducation();
		safeeducation=safeEducationService.getSafeDetailsByEid(eid);
		int readno=safeeducation.getReadno();
		readno++;//访问一次详情，阅读量加一
		safeEducationService.addReadno(eid, readno);
		return Msg.cuccess().add("safedetails", safeeducation);
	}
}
